package com.edwin.websitebe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edwin.websitebe.mapper.SchemeMapper;
import com.edwin.websitebe.model.Scheme;
import com.edwin.websitebe.service.SchemeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class SchemeServiceImpl extends ServiceImpl<SchemeMapper, Scheme> implements SchemeService {

    @Override
    public Page<Scheme> pageList(Scheme scheme) {
        LambdaQueryWrapper<Scheme> wrapper = new QueryWrapper<Scheme>().lambda()
                .like(StringUtils.isNotEmpty(scheme.getSchemeTitle()), Scheme::getSchemeTitle, scheme.getSchemeTitle())
                .orderByAsc(Scheme::getSort)
                .orderByDesc(Scheme::getCreateTime);
        return this.page(Page.of(scheme.getPage(), scheme.getPageSize()), wrapper);
    }
}
